package com.xenstra.rhodiumone.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionUtil {

	private static ConnectionUtil instance;
	
	private ConnectionUtil(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static ConnectionUtil getInstance(){
		if(instance == null){
			instance = new ConnectionUtil();
		}
		return instance;
	}
	
	public Connection getConnection(){
		try {
			return DriverManager.getConnection("jdbc:mysql://localhost:3306/test","bills","AgreeYa!@#$");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public void close(Connection con){
		try {
			if(con != null && ! con.isClosed()){
				con.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
